<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">

	<ui:define name="content">

		<f:event type="preRenderView"
			listener="#{sessionController.beforeSearchSupervisor}" />

		<div class="title ui-widget-header ui-corner-all">
			<h:panelGrid style="margin:auto;">
		BUSCAR SESIONES
		</h:panelGrid>

		</div>

		<h:form id="formSearch">

			<h:panelGrid style="margin:auto;">

				<h:panelGrid style="margin:auto;text-align:center;">
					<p:messages id="messages"></p:messages>
				</h:panelGrid>

				<h:panelGrid columns="3">

					<h:panelGrid columns="2">


						<p:outputLabel value="Fecha"></p:outputLabel>
						<p:calendar pattern="dd-MM-yyyy"
							value="#{sessionController.startedAt}" required="true"
							requiredMessage="Debe seleccionar fecha"></p:calendar>

						<p:outputLabel value="Campaña"></p:outputLabel>
						<p:selectOneMenu id="campaign" required="true"
							requiredMessage="Debe seleccionar campaña"
							value="#{sessionController.campaignSelected}">
							<f:selectItem itemValue="" itemLabel="Seleccione.."></f:selectItem>
							<f:selectItem itemValue="t" itemLabel="Todos"></f:selectItem>
							<f:selectItems value="#{sessionController.campaigns}"></f:selectItems>
							<p:ajax listener="#{sessionController.searchSupervisors}" 
								update=":formSearch:supervisors :formSearch:messages"></p:ajax>
						</p:selectOneMenu>

						<p:outputLabel value="Supervisor"></p:outputLabel>
						<p:selectOneMenu id="supervisors"
							value="#{sessionController.supervisorSelected}">
							<f:selectItem itemValue="" itemLabel="Seleccione.."></f:selectItem>
							<f:selectItem itemValue="t" itemLabel="Todos"></f:selectItem>
							<f:selectItems value="#{sessionController.supervisors}"></f:selectItems>
						</p:selectOneMenu>


						<p:outputLabel value="Tipo de sesion"></p:outputLabel>
						<p:selectOneMenu id="sessionType" required="true"
							requiredMessage="Debe seleccionar tipo de sesion"
							value="#{sessionController.sessionTypeSelected}">
							<f:selectItem itemValue="" itemLabel="Seleccione.."></f:selectItem>
							<f:selectItem itemValue="t" itemLabel="Todos"></f:selectItem>
							<f:selectItems value="#{sessionController.sessionTypes}"></f:selectItems>
						</p:selectOneMenu>





					</h:panelGrid>

					<h:panelGrid columns="2">

						<p:outputLabel value="Estado"></p:outputLabel>
						<p:selectOneMenu id="estado"
							value="#{sessionController.openSessionsSelected}">
							<f:selectItem itemValue="" itemLabel="Seleccione.."></f:selectItem>
							<f:selectItem itemValue="true" itemLabel="Abiertas"></f:selectItem>
							<f:selectItem itemValue="false" itemLabel="Cerradas"></f:selectItem>
						</p:selectOneMenu>

						<p:outputLabel value="Host"></p:outputLabel>
						<p:inputText style="width: 180px;"
							value="#{sessionController.sessionHost}"></p:inputText>

						<p:outputLabel value="Anexo"></p:outputLabel>
						<p:inputText style="width: 180px;"
							value="#{sessionController.sessionPeer}"></p:inputText>

						<p:outputLabel value="Codigo"></p:outputLabel>
						<p:inputText style="width: 180px;"
							value="#{sessionController.agentCode}"></p:inputText>


					</h:panelGrid>

					<h:panelGrid columns="2">



						<p:outputLabel value="Usuario"></p:outputLabel>
						<p:inputText style="width: 180px;"
							value="#{sessionController.agentUsername}"></p:inputText>

						<p:outputLabel value="Nombre"></p:outputLabel>
						<p:inputText style="width: 180px;"
							value="#{sessionController.agentName}"></p:inputText>

						<p:outputLabel value="DNI"></p:outputLabel>
						<p:inputText style="width: 180px;"
							value="#{sessionController.agentDocumentNumber}"></p:inputText>




					</h:panelGrid>

				</h:panelGrid>

				<h:panelGrid columns="3" style="margin:auto;text-align:center;">
					<p:commandButton icon="ui-icon-search"
						actionListener="#{sessionController.searchSupervisorSessions}"
						value="Buscar" process="@form"
						update=":formSearch:searchTable :formSearch:messages">
					</p:commandButton>

				</h:panelGrid>

			</h:panelGrid>

			<p:dataTable value="#{sessionController.sessions}" var="s"
				rowKey="#{s.id}" paginator="true" rows="10" id="searchTable"
				selectionMode="single">


				<p:column headerText="Campaña" sortBy="#{s.campaign.name}">
					<h:outputText value="#{s.campaign.name}"></h:outputText>
				</p:column>

				<p:column headerText="Supervisor"
					sortBy="#{s.agent.supervisor.firstname} #{s.agent.supervisor.lastname}">
					<h:outputText
						value="#{s.agent.supervisor.firstname} #{s.agent.supervisor.lastname}"></h:outputText>
				</p:column>

				<p:column headerText="Host" sortBy="#{s.host}">
					<h:outputText value="#{s.host}"></h:outputText>
				</p:column>

				<p:column headerText="Anexo" sortBy="#{s.peer}">
					<h:outputText value="#{s.peer}"></h:outputText>
				</p:column>

				<p:column headerText="DNI" sortBy="#{s.agent.documentNumber}">
					<h:outputText value="#{s.agent.documentNumber}"></h:outputText>
				</p:column>

				<p:column headerText="Usuario" sortBy="#{s.agent.username}">
					<h:outputText value="#{s.agent.username}"></h:outputText>
				</p:column>

				<p:column headerText="Agente"
					sortBy="#{s.agent.firstname} #{s.agent.lastname}">
					<h:outputText value="#{s.agent.firstname} #{s.agent.lastname}"></h:outputText>
				</p:column>

				<p:column headerText="Codigo" sortBy="#{s.agent.code}">
					<h:outputText value="#{s.agent.code}"></h:outputText>
				</p:column>

				<p:column headerText="Tipo" sortBy="#{s.sessionType.name}">
					<h:outputText value="#{s.sessionType.name}"></h:outputText>
				</p:column>

				<p:column headerText="Inicio" sortBy="#{s.startedAt}">
					<h:outputText value="#{s.startedAt}">
						<f:convertDateTime pattern="dd-MM-yyyy HH:mm:ss"
							timeZone="America/Lima" />
					</h:outputText>
				</p:column>

				<p:column headerText="Fin" sortBy="#{s.endedAt}">
					<h:outputText value="#{s.endedAt}">
						<f:convertDateTime pattern="dd-MM-yyyy HH:mm:ss"
							timeZone="America/Lima" />
					</h:outputText>
				</p:column>
				<p:column headerText="Duración" sortBy="#{s.endedAtTempury}">
					<h:outputText value="#{s.endedAtTempury}">
					</h:outputText>
				</p:column>

			</p:dataTable>


		</h:form>
	</ui:define>

</ui:composition>
</html>
